/*
 * @Author: your name
 * @Date: 2020-08-04 21:45:52
 * @LastEditTime: 2021-03-18 22:09:44
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \adminPC\src\api\user.js
 */
import request from '@/utils/request'
const basePath = '/jpower-auth'
export function login(params) {
  const { code, key, ...data } = params
  return request({
    url: basePath + '/auth/login',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Captcha-Code': code,
      'Captcha-Key': key,
      'Tenant-Code': params.tenantCode
    },
    method: 'post',
    params: data
  })
}

export function getInfo(token) {
  return Promise.resolve({
    code: 20000,
    data: {
      roles: ['admin'],
      introduction: 'I am a super administrator',
      avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
      name: 'Super Admin'
    }
  })
}

/**
 * @description:退出登录
 * @param {String} userId
 * @return {promise}
 */
export function logout(userId) {
  return request({
    url: basePath + '/auth/loginOut',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    method: 'post',
    params: { userId }
  })
}

export const getCaptcha = () => request({
  url: basePath + '/auth/captcha',
  method: 'get'
})

export const sendCode = (data) => {
  return request({
    url: basePath + '/auth/phoneCaptcha',
    method: 'get',
    meta: {
      isToken: false,
      isSerialize: true
    },
    params: data
  })
}
